package com.cn.wanxi.util.servlet;

import com.cn.wanxi.util.model.NewsModel;
import com.cn.wanxi.util.model.SchoolNewsModel;
import com.cn.wanxi.util.service.impl.NewsService;
import com.cn.wanxi.util.service.impl.SchoolContent2Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/news")
public class NewsServlet extends HomeServletServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.doGet(req, resp);
        HttpSession session = req.getSession();
        NewsService newsService =new NewsService();
        SchoolContent2Service schoolContent2Service =new SchoolContent2Service();
//        页面小导航
        List<SchoolNewsModel> schoolNewsModels = schoolContent2Service.getSchoolNewsModel();
        req.setAttribute("schoolNewsModels",schoolNewsModels);
//        页面新闻
        List<NewsModel> newsModels = newsService.getNeasModel();
        req.setAttribute("newsModels",newsModels);
        gotoNews(req,resp);
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        gotoNews(req,resp);
    }
    private void gotoNews(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/jsp/news.jsp").forward(req,resp);
    }
}
